# -*- coding: utf-8 -*-

from django.db import models
import time

# Create your models here.
class Game(models.Model):
    TYPE_FORMAL = 'f'
    TYPE_PRACTICE = 'p'
    TYPE_CHOICES = (
                    (TYPE_FORMAL, 'formal'),
                    (TYPE_PRACTICE, 'practice'),
                    )
    type = models.CharField(max_length=2,
                            choices = TYPE_CHOICES,
                            default = TYPE_FORMAL)
    name = models.CharField(max_length=200)
    dateTime = models.DateTimeField()
    
    country = models.CharField(max_length=200)
    county = models.CharField(max_length=200)
    field = models.CharField(max_length=200)
    umpires = models.CharField(max_length=300)
    
    temperature = models.FloatField()
    humidity = models.FloatField()
    windSpeed = models.FloatField()
    
    def __unicode__(self):
        out_str = '' + str(self.date) + " " + self.name
        return out_str

class Record(models.Model):
    game = models.ForeignKey(Game)
    number = models.IntegerField()
    name = models.CharField(max_length=20)
    gender = models.CharField(max_length=1)
    totalRank = models.IntegerField()
    genderRank = models.IntegerField()
    records = models.FloatField()   # record in seconds
    avgspeed = models.FloatField()  # record in seconds
    
    #field_map = ['number', 'name', 'gender', 'totalRank', 'genderRank', 'records', 'avgspeed']
    #field_type = [conv_int, conv_str, conv_gender, conv_int, conv_int, conv_date, conv_date]
        
    def __unicode__(self):
        out_str = '' + self.game.name + "_" + str(self.number) + self.name
        return out_str
    
    def records_in_minutes_str(self):
        return  time.strftime('%H:%M:%S', time.gmtime(self.records))
    
    def speed_in_minutes_str(self):
        return  time.strftime('%H:%M:%S', time.gmtime(self.avgspeed))